import { getWithErrorMessage, putWithErrorMessage, postWithErrorMessage } from '@/utils/http/Axios'

export function fetchCaptcha() {
  return postWithErrorMessage<Captcha>('/base/api/v1/captcha/image').then(resp => resp.data)
}

export function login(loginForm: LoginForm): Promise<LoginResponse> {
  return postWithErrorMessage<LoginResponse>('/base/api/v1/login', loginForm).then(resp => resp.data)
}

export function fetchUserInfo(): Promise<UserInfoResponse> {
  return getWithErrorMessage<UserInfoResponse>('/base/api/v1/user/userinfo').then(resp => resp.data)
}

export function updatePassword(form: {
  mobile: string
  oldPassword: string
  originalNewPassword: string
  password: string
}) {
  return putWithErrorMessage('/base/api/v1/user/password/old_password', form).then(resp => resp.data)
}

export const fetchSystemInfo = async (url: string) => {
  return postWithErrorMessage('/base/api/v1/product/url', {
    url: url
  })
}
// 通过产品CODE获取当前产品信息
export function fetchProductByCode(code: string) {
  return getWithErrorMessage(`/base/api/v1/product/detail/${code}`);
}
// 通过租户CODE获取租户信息
export function fetchTenantByCode(code: string) {
  return getWithErrorMessage(`/base/api/v1/tenant/detail/${code}`);
}
